<?php
/**
 * TestUnit - simple aid alá JUnit... not so powerfull.
 *
 * @author Martin "DevelX" Jurča
 * @version 2009-02-08
 */
class TestUnit {
    protected $tests = array();
    protected $unitName = '';

    protected function assertTrue($cond, $msg) {
        if (!$cond) {
            throw new Exception($msg);
        }
    }

    protected function assertFalse($cond, $msg) {
        if ($cond) {
            throw new Exception($msg);
        }
    }

    protected function assertNull($expr, $msg) {
        if ($expr !== null) {
            throw new Exception($msg);
        }
    }

    protected function setUpClass() {}

    protected function tearDownClass() {}

    protected function setUpTest() {}

    protected function tearDownTest() {}

    public function runTest() {
        echo "Running tests of {$this->unitName}...\n";
        $this->setUpClass();
        foreach ($this->tests as $test) {
            echo "Running test $test: ";
            $this->setUpTest();
            try {
                $this->{$test}();
                echo "OK\n";
            } catch (Exception $e) {
                echo "{$e->getMessage()}\n";
            }
            $this->tearDownTest();
        }
        $this->tearDownClass();
        echo "\n";
    }
}
?>
